package com.yunchao.feature.business.data.datasource.api.mapper

import com.yunchao.feature.business.data.datasource.database.model.BusinessInfoEntityModel
import com.yunchao.feature.business.data.datasource.database.model.BusinessPackEntityModel
import com.yunchao.feature.business.domain.model.BusinessInfoModel
import com.yunchao.feature.business.domain.model.BusinessPackModel
import com.yunchao.feature.business.data.datasource.api.model.CommonApiModel
import com.yunchao.feature.business.data.datasource.api.model.CommonApiModel.CommonPackApiModel
import kotlin.collections.map


internal fun CommonApiModel.toEntityModel() = BusinessInfoEntityModel(
    tranTypeID = tranTypeID.orEmpty(),
    tranID = tranID.orEmpty(),
    chkUserId = chkUserId.orEmpty(),
    sequency = sequency.orEmpty(),
    giveDataTime = giveDataTime.orEmpty(),
    giveOperator = giveOperator.orEmpty(),
    cardID = cardID.orEmpty(),
    busiInfoList = busiInfoList?.map { it.toEntityModel() } ?: emptyList(),
    packInfoList = packInfoList?.map { it.toEntityModel() }
        ?: stockPackInfoList?.map { it.toEntityModel() } ?: emptyList(),
    packInfoPayloads = emptyList()
)

internal fun CommonApiModel.toDomainModel() = BusinessInfoModel(
    tranTypeID = tranTypeID.orEmpty(),
    tranID = tranID.orEmpty(),
    chkUserId = chkUserId.orEmpty(),
    sequency = sequency.orEmpty(),
    giveDataTime = giveDataTime.orEmpty(),
    giveOperator = giveOperator.orEmpty(),
    cardID = cardID.orEmpty(),
    busiInfoList = busiInfoList?.map { it.toDomainModel() } ?: emptyList(),
    packInfoList = packInfoList?.map { it.toDomainModel() }
        ?: stockPackInfoList?.map { it.toDomainModel() } ?: emptyList(),
    packInfoPayloads = emptyList()
)

/**
 *   val currency: String,
 *     val condomId: String,
 *     val condomName: String,
 *     val editionId: String,
 *     val editionName: String,
 *     val number: String,
 *     val flag: String,
 *     val scanResult: String
 */
internal fun CommonPackApiModel.toEntityModel() = BusinessPackEntityModel(
    voucherTypeName = voucherTypeName.orEmpty(),
    value = value.orEmpty(),
    paperTypeID = paperTypeID.orEmpty(),
    paperTypeName = paperTypeName.orEmpty(),
    sackMoney = sackMoney.orEmpty(),
    sackNo = sackNo.orEmpty(),
    voucherTypeId = voucherTypeId.orEmpty(),
    bundles = bundles.orEmpty(),
    tie = tie.orEmpty(),
    oprDT = oprDT.orEmpty(),
    totalMoney = totalMoney.orEmpty(),
    mustOutFlag = mustOutFlag.orEmpty(),
    currency = "",
    condomId = "",
    condomName = "",
    editionId = "",
    editionName = "",
    number = "",
    flag = "",
    scanResult = ""
)

internal fun CommonPackApiModel.toDomainModel() = BusinessPackModel(
    voucherTypeName = voucherTypeName.orEmpty(),
    value = value.orEmpty(),
    paperTypeID = paperTypeID.orEmpty(),
    paperTypeName = paperTypeName.orEmpty(),
    sackMoney = sackMoney.orEmpty(),
    sackNo = sackNo.orEmpty(),
    voucherTypeId = voucherTypeId.orEmpty(),
    bundles = bundles.orEmpty(),
    tie = tie.orEmpty(),
    oprDT = oprDT.orEmpty(),
    totalMoney = totalMoney.orEmpty(),
    mustOutFlag = mustOutFlag.orEmpty(),
    currency = "",
    condomId = "",
    condomName = "",
    editionId = "",
    editionName = "",
    number = "",
    flag = "",
    scanResult = ""
)
